package com.itheima.servlet;

import com.itheima.domain.User;
import com.itheima.service.Service;
import com.itheima.service.ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/*")
public class UserServlet extends BaseServlet {

    public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Service service = new ServiceImpl();
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        User u = service.login(username, password);
        if(u==null){
            System.out.println("false");
            resp.sendRedirect(req.getContextPath() + "/login.jsp");
        }else{
            System.out.println("true");
            resp.sendRedirect(req.getContextPath() + "/emp/listByPage");
        }
    }
}
